package org.westos.ChinaSoft3;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class reflectEmployee {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, CloneNotSupportedException {

        //反射创建对象
        Class<?> aClass = Class.forName("org.westos.ChinaSoft3.Employee");
        Constructor<?>[] constructors = aClass.getDeclaredConstructors();
        Employee o = (Employee) constructors[0].newInstance(1, "zhangsan", 23, "N", 5200);
        Employee o1 = (Employee) constructors[0].newInstance(2, "lisi", 24, "N", 5300);
        System.out.println(o);
        System.out.println(o1);

        //克隆创建对象
        Employee employee = new Employee(1, "zhangsan", 25, "N", 5200);
        Employee employee2 = (Employee) employee.clone();
        employee2.setId(2);
        employee2.setName("lisi");
        employee2.setSex("N");
        employee2.setAge(26);
        employee2.setSA(5600);

        System.out.println(employee);
        System.out.println(employee2);

    }
}
